import subprocess
import os
import math



def WaDE(IMG_Path='3.ppm',filePath="keypoints.txt"):
    if(os.path.isfile(filePath)):
        
        #os.remove() function to remove the file
        os.remove(filePath)
        
        #Printing the confirmation message of deletion
        print("File Deleted successfully")
    else:
        print("File does not exist")
    #Showing the message instead of throwig an error
        

    result=subprocess.call(['./WaveDetector','-i',IMG_Path],)


    ######################### GetKeyPoints
    with open(filePath, 'r') as file:
        lines = file.readlines()

    data = []
    for line in lines[2:]:
        values = line.strip().split()
        x = int(values[0])
        y = int(values[1])
        a = float(values[2])
        b = int(values[3])
        c = float(values[4])
        data.append((x, y, a, b, c))

    num_Keypoints=len(data)
    print(num_Keypoints)

    final_data=[]
    for tempdata in data:
        x=tempdata[0]
        y=tempdata[1]
        r=math.sqrt(1/tempdata[2])
        final_data.append((x,y,r))

    print(final_data)


if __name__ == '__main__':
    WaDE()
# print(result.returncode)